package com.primb.bench.project.home.model;

import com.primb.bench.common.module.http.service.ApiClient;
import com.primb.bench.common.module.http.service.ApiService;
import com.primb.bench.project.home.contract.PromiseApplyContract;
import com.primb.bench.project.home.entity.HttpProInfo;
import com.primb.bench.project.home.entity.HttpPromiseEntity;
import com.primb.bench.project.home.entity.LoanCalculateInfoEntity;
import com.primb.bench.project.home.entity.PromiseApplyEntity;
import com.primb.netlibs.converter.RxSchedulerUtils;

import java.util.HashMap;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by Administrator on 2017/05/18
 */

public class PromiseApplyModelImpl implements PromiseApplyContract.Model {
    @Override
    public  Observable<HttpProInfo> getPromiseInfo(String custId) {
        return ApiClient.initService(ApiService.class).getPromiseInfo(custId).compose(RxSchedulerUtils.normalSchedulersTransformer());
    }

    @Override
    public Observable<HttpPromiseEntity> getCalculateGoodRate(LoanCalculateInfoEntity infoEntity) {
        HashMap<String, String> map = new HashMap<>();
        map.put("priceId", infoEntity.getLogoInfoEntity().getLogoNumber());
        map.put("custGdIr", infoEntity.getResultInfoEntity().getLnpCustRate());
        map.put("lnCostIr", infoEntity.getResultInfoEntity().getLnpCustRate());
        map.put("paraPrdTarRet", infoEntity.getResultInfoEntity().getLnpTargetRate());
        map.put("custId", infoEntity.getClientInfoEntity().getCustomerNum());
        map.put("custName", infoEntity.getClientInfoEntity().getCustomerName());
        map.put("prdtId", infoEntity.getLoanInfoEntity().getLoanBusinessTypeId());
        map.put("lnAmt", infoEntity.getLoanInfoEntity().getLoanMoney());
        map.put("sceneBgnDate", infoEntity.getPromiseApplyEntity().getPromiseStartDate().replace("-",""));
        map.put("sceneEndDate", infoEntity.getPromiseApplyEntity().getPromiseEndDate().replace("-",""));
        map.put("nowDpMonAvg", infoEntity.getPromiseApplyEntity().getPromiseDepositDayNow());
        map.put("nowDpMonBal", infoEntity.getPromiseApplyEntity().getPromiseDepositSumNow());

        if (infoEntity.getPromiseApplyEntity().getPromiseDepositDay() != null)
            map.put("sceneCurDpAvg", infoEntity.getPromiseApplyEntity().getPromiseDepositDay());
        else
            map.put("sceneCurDpAvg", "");
        if (infoEntity.getPromiseApplyEntity().getPromiseDepositDay() != null)
            map.put("sceneCurDpBal", infoEntity.getPromiseApplyEntity().getPromiseDepositSum());
        else
            map.put("sceneCurDpBal", "");
        map.put("promBaseAcc", infoEntity.getPromiseApplyEntity().isPromiseBasicAccount() ? "1" : "0");
        map.put("promForCurAcc", infoEntity.getPromiseApplyEntity().isPromiseSettleAccount() ? "1" : "0");
        map.put("promPayAcc", infoEntity.getPromiseApplyEntity().isPromiseSalaryAccount() ? "1" : "0");
        map.put("othPromScene", infoEntity.getPromiseApplyEntity().getPromiseOtherSceneDetail());
        map.put("othPromPoint", infoEntity.getPromiseApplyEntity().getPromiseOtherScene());
        map.put("remark", infoEntity.getPromiseApplyEntity().getPromiseRemark());
        map.put("orgId", infoEntity.getLogoInfoEntity().getLogoPartId());
        map.put("userId", infoEntity.getLogoInfoEntity().getLogoManagerNum());

        return ApiClient.initService(ApiService.class).getCalculateGoodRate(map).compose(RxSchedulerUtils.normalSchedulersTransformer());
    }
}